<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head th:replace="/user/common/CSSandJS1 :: head('订单信息编辑')"></head>

<body>



  <!--== End Preloader Content ==-->
  <div th:replace="/user/common/header :: header(${cartList}, ${totalMoney})"></div>
  <main class="main-content" >
    <div class="page-header-area">
      <div class="container">
        <div class="row">
          <div class="col-12 text-center">
            <div class="page-header-content">
              <h4 class="title mt-0">Fill Your Order</h4>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!--== Start Product Area Wrapper ==-->
    <section class="product-area product-information-area">

      <div class="container">
        <div class="product-information">
          <div class="row">
            <div class="col-lg-7">
<!--              <form id="form" action="">-->
                <div class="edit-checkout-head">
                  <div class="header-logo-area">
                    <a href="index.html">
                      <img class="logo-main" th:src="@{/user/img/logo.png}" alt="Logo">
                    </a>
                  </div>
                  <div class="breadcrumb-area">
                    <ul>
                      <li><a style="font-size: 20px" class="active" href="cart.html" >购物车</a><i class="fa fa-angle-right"></i></li>
                      <li><span style="font-size: 15px;font-weight: bold">订&nbsp;&nbsp;单</span><i class="fa fa-angle-right"></i></li>
                      <li><a style="font-size: 20px" class="active" href="cart.html" >首&nbsp;&nbsp;页</a></li>
                    </ul>
                  </div>
                </div>
                <div class="edit-checkout-information">

                  <h4 class="title">Contact information</h4>
                  <!--                <div class="logged-in-information">-->
                  <!--                  <div class="thumb" data-bg-img="/static/img/photos/gravatar2.png"></div>-->
                  <!--                  <p>-->
                  <!--                    <span class="name">julie</span>-->
                  <!--                    <span>(julie@example.com)</span>-->
                  <!--                    <a href="login.html">Log out</a>-->
                  <!--                  </p>-->
                  <!--                </div>-->
                  <!--                <div class="form-check form-check-inline">-->
                  <!--                  <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">-->
                  <!--                  <label class="form-check-label" for="inlineCheckbox1">Keep me up to date on news and exclusive offers</label>-->
                  <!--                </div>-->
                  <div class="edit-checkout-form">

                    <h4 class="title">填写订单信息</h4>
                    <div class="row row-gutter-12">
                      <div class="col-lg-6">
                        <div class="form-floating">
                          <input name="name" type="text" class="form-control" id="floatingInputGrid" placeholder="name" th:value="${session.user.getUsername()}">
                          <label for="floatingInputGrid">收件人姓名</label>
                        </div>
                      </div>
                      <div class="col-lg-12">
                        <div class="form-floating">
                          <input name="address" type="text" class="form-control" id="floatingInput3Grid" placeholder="address" th:value="${session.user.getAddress()}">
                          <label for="floatingInput3Grid">收件地址</label>
                        </div>
                      </div>
                      <div class="col-lg-12">
                        <div class="form-floating">
                          <input name="phone" type="text" class="form-control" id="floatingInput4Grid" placeholder="address" th:value="${session.user.getPhone()}">
                          <label for="floatingInput4Grid">手机号</label>
                        </div>
                      </div>
                      <div class="col-lg-6">
                        <div class="form-floating">
                          <select data-form="formed" name="delivery" class="form-select form-control" id="floatingInput6rid" aria-label="Floating label select example">
                            <option selected>中通快递</option>
                            <option>圆通快递</option>
                            <option>顺丰快递</option>
                          </select>
                          <div class="field-caret"></div>
                          <label for="floatingInput6rid">选择快递</label>
                        </div>
                      </div>
                      <div class="col-lg-6">
                        <div class="form-floating">
                          <input name="code" type="text" class="form-control" id="floatingInput7Grid" placeholder="address" th:value="${session.user.getZipCode()}">
                          <label for="floatingInput7Grid">邮政编码</label>
                        </div>
                      </div>
                      <div class="col-12">
                        <div class="btn-box">
                          <button th:id="createOrder_btn"  style="font-weight: bold;font-size: 20px;" class="btn-shipping" >支&nbsp;&nbsp;付</button>
                          <a class="btn-return" href="cart.html">返回购物车</a>
                        </div>
                      </div>

                    </div>

                  </div>
                </div>
              </form>
            </div>
            <div class="col-lg-5">
            <div class="shipping-cart-subtotal-wrapper">
              <div class="shipping-cart-subtotal">
                <div class="shipping-cart-item" th:each="cart:${cartList}">
                  <div class="thumb">
                    <img th:src="@{${cart.tProduct.photo}}" alt="">
                    <span class="quantity" >[[${cart.count}]]</span>
                  </div>
                  <div class="content">
                    <h4 class="title">[[${cart.tProduct.title}]]</h4>
                    <!--                      <span class="info">s / purple / metal</span>-->
                    <span class="price">￥[[${#numbers.formatDecimal(cart.tProduct.price * cart.tProduct.discount * cart.count, 0, 2)}]]</span>
                  </div>
                </div>

                <div class="shipping-subtotal">
                  <p><span>件&nbsp;&nbsp;数</span><span><strong>X [[${totalCount}]]</strong></span></p>
                  <p><span>Shipping</span><span>Calculated at next step</span></p>
                </div>
                <div class="shipping-total">
                  <p class="total">总&nbsp;&nbsp;计</p>
                  <p class="price"><span class="usd">YUAN</span>￥[[${totalMoney}]]</p>
                </div>
              </div>
            </div>
          </div>
          </div>
        </div>
      </div>
    </section>
    <!--== End Product Area Wrapper ==-->
<!--    <div class="edit-checkout-footer">-->
<!--      <p>All rights reserved Demo julie</p>-->
<!--    </div>-->
  </main>

  <!--== Scroll Top Button ==-->
  <div id="scroll-to-top" class="scroll-to-top"><span class="fa fa-angle-double-up"></span></div>
  <!--== Start Quick View Menu ==-->
  <div th:replace="/user/common/aside :: aside"></div>
  <!--== End Quick View Menu ==-->



<div th:replace="/user/common/CSSandJS1 :: js"></div>
  <button th:id="test">test</button>
  <input th:id="tt" value="132">
<script th:inline="javascript">
  $("#test").click(function () {
    let tt = JSON.stringify([[${cartList}]]);
      Object =[[${cartList}]];
      console.log(tt);
      $("#tt").val(tt);
  });
  $("#createOrder_btn").click(function () {
      let name = $("#floatingInputGrid").val();
      let phone = $("#floatingInput4Grid").val();
      let address = $("#floatingInput3Grid").val();
      let delivery = $("#floatingInput7Grid").val();
      let code = $("#floatingInput6rid").val();
      // let cartList = $.parseJSON([[${cartList}]]);
      let car = JSON.stringify([[${cartList}]]);
      let totalMoney = [[${totalMoney}]];
      //$("#tt").val('[{"id":24,"userId":4,"productId":1,"count":1,"createTime":"2021-12-26T13:45:48.000+08:00","updateTime":"2021-12-26T13:45:48.000+08:00","tproduct":{"id":24,"createTime":"2021-12-26T13:45:48.000+08:00","updateTime":"2021-12-26T13:45:48.000+08:00","code":"234234","kind":"23423","note":"12qweqeqswad","price":1000,"stock":12,"title":"七彩虹RTX2080TI","discount":1,"producer":null,"photo":"/user/img/shop/1.jpg","score":3.6,"lookNumber":42}},{"id":25,"userId":4,"productId":3,"count":2,"createTime":"2021-12-26T13:55:12.000+08:00","updateTime":"2021-12-26T13:55:23.000+08:00","tproduct":{"id":25,"createTime":"2021-12-26T13:55:12.000+08:00","updateTime":"2021-12-26T13:55:23.000+08:00","code":"001","kind":"衣服","note":"蓝色小花吊带裙子，蝴蝶结腰带","price":156,"stock":260,"title":"兰花裙","discount":0.85,"producer":"厦门贵人鸟有限公司","photo":"/user/img/shop/2.jpg","score":1,"lookNumber":9}}]');
      // let car =$("#tt").val();
    // window.location.href = "/topay?name="+name+"&phone="+phone+"&address="+address
    //                           +"&delivery="+delivery+"&code="+code+"&totalMoney="+[[${totalMoney}]]+"&cartList=";
    console.log(car);
    $.ajax({
        url: "/tOrder/createOrder",
        type:"get",//String address, String delivery, String code, Float totalMoney,
        data:{ "car":car,"name": name, "phone": phone,"address":address, "delivery":delivery, "code":code, "totalMoney":[[${totalMoney}]]},
        // dataType: "json",
        success: function (res) {
          if (res.length != 0){
            layer.msg('成功！');
            window.location.href = "/pay?totalMoney="+totalMoney+"&orderId="+res;
          }else{
            layer.msg('失败！');
          }

        }
    })
  })
</script>
</body>

</html>